<?php
// $Id$

/**
 * Controller_Admin_Web 控制器
 */
class Controller_Admin_activity extends Controller_Abstract {
	
	/**
	 * 活动
	 */
	function actionIndex()
	{
		$this->union_table = activitysignup::meta();
		$this->lists();
	}
	 
	/**
	 * 活动设置
	 */
	 
	function actionAdd() {
	    //设置要操作的表单，并设置自动插入方式
	    $this->union_table = activitysignup::meta ();

	    $handle = new helper_autoinsert ( $this->union_table );
	    $form = new Form_activity_add ( url ( $this->_context->controller_name . '/' . $this->_context->action_name ) );
	    //这里面会自动将get方式获取的参数传递到表单里面去的
	    $result = $handle->add ( $form, 'id', $_GET );
	    if ($this->_context->isGET ()) {
	        //传递$form值
	        $this->_view ['form'] = $result;
	        $this->_viewname = '../form/add';
	        $form->element('acct_id')->value = $_SESSION['acct']['id'];
	        if($this->_context->id){
	        	$info = activitysignup::find(array("id"=>$this->_context->id))->getOne();
	        	$form->element('starttime')->value = str_replace("CS", '', date("Y-m-dTH:i",$info->starttime)) ;
	        	$form->element('endtime')->value = str_replace("CS", '', date("Y-m-dTH:i",$info->endtime));
	        }
	    } else {
	    	

		    
		    
	        //记录日志
	        if(!$_POST['id'])	{
	            Syslog::logs ( '添加活动,id :' . $handle->form_database_obj->id );
	        }else{
	            Syslog::logs ( '编辑活动,id :' . $handle->form_database_obj->id );
	        }

	        //重新设置时间
	        $info = activitysignup::find(array("id"=>$handle->form_database_obj->id))->getOne();
	        $info->starttime = strtotime($this->_context->starttime);
	        $info->endtime = strtotime($this->_context->endtime);
	        $info->save();

	        if($handle->status=='success')
	            $this->_context->forwardUrl = url("activity/index");
	        return call_user_func_array(array($this,$handle->status),array($result));
	    }
	     
	}
	 
	/**
	 * 删除顶部广告
	 */
	function actionDel() {
	     Syslog::logs("删除活动，ID：".print_r($this->_context->ids,true));
	     $this->union_table = activitysignup::meta();
	     $this->delete(array('id'=>$this->_context->ids));    	  
	}

	function actionList(){
		$this->union_table = activityorder::meta();
		$append =array('is_pay'=>1);
		$this->lists($append);
	}

	function actionset(){
		$this->union_table = activitysignupset::meta();
		$this->_view ['activity_id'] = $this->_context->activity_id;
		$this->lists();
	}
	function actionsetadd(){
		$this->_view['activity_id'] = $this->_context->activity_id;
	    if ($this->_context->isGET ()) {
	    	if($this->_context->id){
	    		$info = activitysignupset::find("id = ".$this->_context->id)->getOne();
	    		$this->_view ['info'] = $info;
	    	}
	    } else {

			if(!empty($this->_context->id)){
				$info = activitysignupset::find("id = ".$this->_context->id)->getOne();
				$info->name=trim($this->_context->name);
				$info->is_must=intval($this->_context->is_must);
				$info->weight=intval($this->_context->weight);
				$info->type=$this->_context->type;
				$info->save(0,'update');
			}else{
				$info = new activitysignupset();
				$info->acct_id=$_SESSION['acct']['id'];
				$info->name=trim($this->_context->name);
				$info->is_must=intval($this->_context->is_must);
				$info->weight=intval($this->_context->weight);
				$info->type=$this->_context->type;
				$info->activity_id=intval($this->_context->activity_id);
				$info->save(0,'create');
			}
	        //记录日志
	        if(!$_POST['id'])	{
	            Syslog::logs ( '添加活动输入,id :' . $info->id );
	        }else{
	            Syslog::logs ( '编辑活动输入,id :' . $info->id );
	        }
	         
	        $this->_context->forwardUrl = url("activity/set")."/activity_id/".$info->activity_id;
	        $this->success('编辑成功');
	    }
	}

	function actionsetDel() {
	     Syslog::logs("删除活动输入，ID：".print_r($this->_context->ids,true));
	     $this->union_table = activitysignupset::meta();
	     $this->delete(array('id'=>$this->_context->ids));
	}



}


